<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet  version="2.0"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xf="http://www.w3.org/2002/xforms">
	
	<xsl:import href="global-vars.xsl" />
	
	<xsl:output media-type="application/xhtml+xml" method="xml" 
		encoding="UTF-8" version="1.0" indent="yes" omit-xml-declaration="no"/>
	
	<xsl:template name="DateTimeTypeInstancePart">
		<xsl:param name="name" />
		<xsl:param name="prefix" />
		
		<xsl:choose>
			<xsl:when test="namespace-uri-for-prefix( $prefix, . ) != $global.ns.target">
				<xsl:element name="{$name}" namespace="{namespace-uri-for-prefix( $prefix, . )}">
					<xsl:value-of select="current-dateTime()" />
				</xsl:element>
			</xsl:when>
			<xsl:otherwise>
				<xsl:element name="{@name}" namespace="{$global.ns.target}" >
					<xsl:value-of select="current-dateTime()" />
				</xsl:element>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="DateTypeInstancePart">
		<xsl:param name="name" />
		<xsl:param name="prefix" />
		
		<xsl:choose>
			<xsl:when test="namespace-uri-for-prefix( $prefix, . ) != $global.ns.target">
				<xsl:element name="{$name}" namespace="{namespace-uri-for-prefix( $prefix, . )}">
					<xsl:value-of select="format-date( current-date(), '[Y0001]-[M01]-[D01]' )" />
				</xsl:element>
			</xsl:when>
			<xsl:otherwise>
				<xsl:element name="{@name}" namespace="{$global.ns.target}" >
					<xsl:value-of select="format-date( current-date(), '[Y0001]-[M01]-[D01]' )" />
				</xsl:element>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="TimeTypeInstancePart">
		<xsl:param name="name" />
		<xsl:param name="prefix" />
		
		<xsl:choose>
			<xsl:when test="namespace-uri-for-prefix( $prefix, . ) != $global.ns.target">
				<xsl:element name="{$name}" namespace="{namespace-uri-for-prefix( $prefix, . )}">
					<xsl:value-of select="format-time( current-time(), '[H01]:[m01]:[s01]' ) " />
				</xsl:element>
			</xsl:when>
			<xsl:otherwise>
				<xsl:element name="{@name}" namespace="{$global.ns.target}" >
					<xsl:value-of select="format-time( current-time(), '[H01]:[m01]:[s01]' ) " />
				</xsl:element>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template name="DateTimeTypeElements">
		<xsl:param name="element.ref" required="yes" />
		<xsl:param name="element.den" required="yes" />
		<xsl:param name="businessterm" required="yes" />
		
		<xsl:element name="div">
			<xsl:attribute name="class" select="replace( replace( $element.den, ' ', '' ), '\.', '__' )"/>
			<xsl:element name="xf:input">
				<xsl:attribute name="ref"><xsl:value-of select="$element.ref"></xsl:value-of></xsl:attribute>
				<xsl:element name="xf:label"><xsl:value-of select="$businessterm"></xsl:value-of></xsl:element>
			</xsl:element>
		</xsl:element>
	</xsl:template>
	
</xsl:stylesheet>
